layui.use(['table','layer','form', 'layedit','jquery'], function(){
  var table = layui.table
      ,layer = layui.layer
      ,form = layui.form
      ,$ = layui.jquery
      ,element = layui.element;

  table.render({
    elem: '#fundFlowTable'
    ,id: 'guestTableItemID'
    ,method: 'post'
    ,url:'../guest/findBalanceFlowByUnionID.json'
    ,where:{unionID:'a011'}
    ,skin: 'line'
    ,even: true //开启隔行背景
    ,response: {
      statusName: 'code'
      ,statusCode: '100012'
      ,msgName: 'msg'
      ,countName: 'total'
      ,dataName: 'data'
    }
    ,cols: [[
       {title:'序号',templet:'#sortNumber',fixed:'left',align:'center',sort: true,unresize: true,}
      ,{field:'total_money', title:'变动金额',align:'center'}
      ,{field:'balance', title:'余额',align:'center'}
      ,{field:'changeReason', title:'变动类型',align:'center'}
      ,{field:'update_time', title:'变动时间',align:'center'}
      ,{field:'remark', title:'备注',align:'center'}
    ]]
    ,page: true
  });

  /*/!*资金流向数据表格*!/
 table.render({
    elem: '#fundFlowTable'
    ,url:'../json/data2.json'
    ,response: {
	    statusName: 'code'
	    ,statusCode: '100012'
	    ,msgName: 'msg'
	    ,countName: 'total'
	    ,dataName: 'data'
    }
    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
      ,curr: 1 //设定初始在第 5 页
      ,groups: 1 //只显示 1 个连续页码
      ,first: false //不显示首页
      ,last: false //不显示尾页
    }
    ,cols: [[
      {field:'id', title: '序号', sort: true}
      ,{field:'changedMoney',title: '变动金额'}
      ,{field:'balance', title: '余额'}
      ,{field:'changeType', title: '变动类型'}
      ,{field:'updateTime', title: '变动时间'}
      ,{field:'remark',title: '备注'}
    ]]
    
  });*/
  
   //一些事件监听
  /*element.on('tab(otherInfos)', function(data){
  	//获取当前选中得tab
  	debugger;
  	var index = data.index;
  	var h1 = $('#liOne').height();
		var h2 = $('#liTwo').height();
		var h3 = $('#liThree').height();
		var h4 = $('#liFour').height();
		console.log(h1);
		console.log(h2);
		console.log(h3);
		console.log(h4);
		
		//$('#fifthBox').css('height',h1+h2);
  	
    
  });*/
  
  //监听折叠
  /*element.on('collapse(test)', function(data){
    layer.msg('展开状态：'+ data.show);
  });*/
 

  //搜索按钮点击事件
  $("#guest_search_id").on('click',function(){
    //获取输入的值
    var guestName = $('#guestName').val();
    var currentSex = $('select[name="sex"] option:selected').text();
    if(currentSex=='选择或输入搜索'){
      currentSex = '';
    }
    console.log('guestName',guestName);
    console.log('currentSex',currentSex);
    table.reload('guestTableID', {
      method: 'get'
      ,where: {
        guestname:guestName,
        sex:currentSex
      }
      , page: {curr: 1}
    });

  });
  
  
  //搜索按钮点击事件
  $("#guest_search_id").on('click',function(){
    //获取输入的值
    var guestName = $('#guestName').val();
    var currentSex = $('select[name="sex"] option:selected').text();
    $.ajax({
      url:'../guest/findGuestsByKeys.json',
      type:'GET',
      async:true,
      data:{
        guestname:guestName,
        sex:currentSex
      },
      timeout:5000,    //超时时间
      dataType:'json', //返回的数据格式：json/xml/html/script/jsonp/text
      success:function(res){
        layer.msg("新增字典类型成功！");
        return true;
      },
      error:function(res){
        layer.msg("新增字典类型出错了！");
        return false;
      },
      complete:function(){
        //刷新父页面数据
        location.reload();
      }
    });
  });

    /*查询用户基本信息*/
    $(function(){
        $.ajax({
            url:'../guest/findGuestInfoByUnionID.json',
            type:'POST',
            async:true,
            data:{
                unionID:'a011',
                orderStatus:1
            },
            timeout:5000,    //超时时间
            dataType:'json', //返回的数据格式：json/xml/html/script/jsonp/text
            success:function(res){
                //解析数组
                $.each(res.data,function (index,content) {
                    //给元素赋值
                    $('#wechatname').html(content.wechat_nickname);//用户昵称
                    $('#phone').html(content.phone);//手机号
                    $('#integral').html(content.integral+'积分');//积分
                    $('#balance').html('￥：'+content.balance);//余额
                    $('#totalOrders').html(content.totalOrdersNum+'/笔');//订单总计
                    $('#totalCost').html('￥：'+content.totalCost);//消费总金额
                    $('#currentMonthOrders').html(content.currentMonthTotalOrdersNum+'/笔');//本月订单
                    $('#currentMonthCost').html('￥：'+content.currentMonthTotalCost);//本月消费金额
                });
                //设置统一高度
                setUnify();
            },
            error:function(res){
                layer.msg("出故障了，请联系管理员！");
            }
        });
    });

  /*给面板设置统一高度*/
  function setUnify(){
	  	var arr1= [];//第一行面板高度数组
	  	var arr2= [];//第二行面板高度数组
	  	//获取面板高度
	  	var h1 = $('#panel1').height();
	  	var h2 = $('#panel2').height();
	  	var h3 = $('#panel3').height();
	  	var h4 = $('#panel4').height();
	  	var h5 = $('#panel5').height();
	  	var h6 = $('#panel6').height();
	  	var h7 = $('#panel7').height();
	  	//对面板高度数组赋值
	  	arr1[0]=h1;
	  	arr1[1]=h2;
	  	arr1[2]=h3;
	  	arr2[0]=h4;
	  	arr2[1]=h5;
	  	arr2[2]=h6;
	  	arr2[3]=h7;
	  	//对数组排序
	  	arr1 = arr1.sort(function(a,b){
	  		return b-a;
	  	});
	  	arr2 = arr2.sort(function(a,b){
	  		return b-a;
	  	});
	  	//给每一行面板设置统一高度，以高度最大的面板高度为准
	  	$('#panel1').css('height',arr1[0]);
	  	$('#panel2').css('height',arr1[0]);
	  	$('#panel3').css('height',arr1[0]);
	  	$('#panel4').css('height',arr2[0]);
	  	$('#panel5').css('height',arr2[0]);
	  	$('#panel6').css('height',arr2[0]);
	  	$('#panel7').css('height',arr2[0]);
	  }
  

  $(function(){


  });
});